package collatz;

public class CollatzExecutions{
	private long grainsize;
	private int threads;
	private boolean alive;
	private Thread threadsrun[];
	private int threadsCreated;

	public CollatzExecutions(long grainsize, int threads){
		this.grainsize = grainsize;
		this.threads = threads;
		this.alive = false;
		this.threadsrun = new Thread[threads + 1];
		this.threadsCreated = 0;

	}


	public void calculate(long numbers[]){		
		int div = numbers.length / this.threads;

		
		for(int i = 0 ; i < this.threads ; i++){
			
			threadsrun[i] = new Thread(new CollatzThread(numbers, i*div+1, (i+1)*div));
		}

		for(int i = 0 ; i < this.threads; i++)
			threadsrun[i].start();

	}

	public boolean isAlive(){
		for(int i = 0 ; i < threads ; i++)
			if(threadsrun[i].isAlive())
				return true;
		
		this.threadsCreated = 0;
		return false;
	}

}